<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <input type="button" value="点击" id="btn">
  <script>
    var btn = document.getElementById("btn");  
    addEvent(btn,"click", fun); 
    function addEvent(ele,type,fn) {
      if (ele.addEventListener) {
        ele.addEventListener(type,fn);
      } 
      else if (ele.attachEvent) {
        ele.attachEvent("on" + type,fn);
      }
      else if (ele.onclick){
        ele.onclick = fn;
      }
    }
    removeEvent(btn,"click", fun); 
     function removeEvent(ele,type,fn) {
      // 浏览器能力检测
      if (ele.removeEventListener) {
        ele.removeEventListener(type,fn);
      } 
      else if (ele.detachEvent) {
        ele.detachEvent("on" + type,fn);
      }
      else if (ele.onclick){
        ele.onclick= null;
      }
    }
    function fun() {
      alert(1);
    }
    </script>
</body>
</html>